package com.yit.cn;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by zhangyanfei on 2019/4/22.
 *
 * @author zhangyanfei
 * @date 2019/04/22
 */
public class ApplicationMain {
    public static void main(String[] args) throws Exception {
        PlanManager planManager = new PlanManager();
        StringBuffer stringBuffer = new StringBuffer("");

        //起始日期
        Date d1 = SchedulingContext.DATE_FORMAT.parse("2019-1-01");
        //结束日期
        Date d2 = SchedulingContext.DATE_FORMAT.parse("2019-12-31");
        Date tmp = d1;
        Calendar dd = Calendar.getInstance();
        dd.setTime(d1);
        while (tmp.getTime() <= d2.getTime()) {
            tmp = dd.getTime();
            stringBuffer.append("日期：" + SchedulingContext.DATE_FORMAT.format(tmp) + ";");
            // 起飞
            stringBuffer.append(planManager.fly(tmp));
            //天数加上1
            dd.add(Calendar.DAY_OF_MONTH, 1);
            stringBuffer.append("\n");
        }
        writeStringToFile(stringBuffer.toString());
    }

    public static void writeStringToFile(String content) {
        try {
            File file = new File("demo.txt");
            PrintStream ps = new PrintStream(new FileOutputStream(file));
            ps.println(content);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
}
